home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / gcc263-src.lha / gcc-2.6.3 / fixinc.svr4 < prev    next >
Text File  |  1994-09-22  |  42KB  |  1,651 lines

  1. #! /bin/sh
  2. #
  3. #   fixinc.svr4  --  Install modified versions of certain ANSI-incompatible
  4. #   native System V Release 4 system include files.
  5. #
  6. #   Written by Ron Guilmette (rfg@ncd.com).
  7. #
  8. # This file is part of GNU CC.
  9. # GNU CC is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2, or (at your option)
  12. # any later version.
  13. # GNU CC is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. # You should have received a copy of the GNU General Public License
  18. # along with GNU CC; see the file COPYING.  If not, write to
  19. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20. #
  21. #    This script munges the native include files provided with System V
  22. #    Release 4 systems so as to remove things which are violations of the
  23. #    ANSI C standard.  Once munged, the resulting new system include files
  24. #    are placed in a directory that GNU C will search *before* searching
  25. #    the /usr/include directory. This script should work properly for most
  26. #    System V Release 4 systems.  For other types of systems, you should
  27. #    use the `fixincludes' script instead.
  28. #
  29. #    See README-fixinc for more information.
  30.  
  31. # Directory containing the original header files.
  32. INPUT=${2-${INPUT-/usr/include}}
  33.  
  34. # Fail if no arg to specify a directory for the output.
  35. if [ x$1 = x ]
  36. then echo fixincludes: no output directory specified
  37. exit 1
  38. fi
  39.  
  40. # Directory in which to store the results.
  41. LIB=${1?"fixincludes: output directory not specified"}
  42.  
  43. # Make sure it exists.
  44. if [ ! -d $LIB ]; then
  45.   mkdir $LIB || exit 1
  46. fi
  47.  
  48. ORIG_DIR=`pwd`
  49.  
  50. # Make LIB absolute if it is relative.
  51. # Don't do this if not necessary, since may screw up automounters.
  52. case $LIB in
  53. /*)
  54.     ;;
  55. *)
  56.      LIB=$ORIG_DIR/$LIB
  57.     ;;
  58. esac
  59.  
  60. echo 'Building fixincludes in ' ${LIB}
  61.  
  62. # Determine whether this filesystem has symbolic links.
  63. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  64.   rm -f $LIB/ShouldNotExist
  65.   LINKS=true
  66. else
  67.   LINKS=false
  68. fi
  69.  
  70. echo 'Making directories:'
  71. cd ${INPUT}
  72. if $LINKS; then
  73.   files=`ls -LR | sed -n s/:$//p`
  74. else
  75.   files=`find . -type d -print | sed '/^.$/d'`
  76. fi
  77. for file in $files; do
  78.   rm -rf $LIB/$file
  79.   if [ ! -d $LIB/$file ]
  80.   then mkdir $LIB/$file
  81.   fi
  82. done
  83.  
  84. # treetops gets an alternating list
  85. # of old directories to copy
  86. # and the new directories to copy to.
  87. treetops="${INPUT} ${LIB}"
  88.  
  89. if $LINKS; then
  90.   echo 'Making internal symbolic directory links'
  91.   for file in $files; do
  92.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  93.     if [ "$dest" ]; then    
  94.       cwd=`pwd`
  95.       # In case $dest is relative, get to $file's dir first.
  96.       cd ${INPUT}
  97.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  98.       # Check that the target directory exists.
  99.       # Redirections changed to avoid bug in sh on Ultrix.
  100.       (cd $dest) > /dev/null 2>&1
  101.       if [ $? = 0 ]; then
  102.     cd $dest
  103.     # X gets the dir that the link actually leads to.
  104.     x=`pwd`
  105.     # If link leads back into ${INPUT},
  106.     # make a similar link here.
  107.     if expr $x : "${INPUT}/.*" > /dev/null; then
  108.       # Y gets the actual target dir name, relative to ${INPUT}.
  109.       y=`echo $x | sed -n "s&${INPUT}/&&p"`
  110.       # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
  111.       dots=`echo "$file" |
  112.         sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
  113.       echo $file '->' $dots$y ': Making link'
  114.       rm -fr ${LIB}/$file > /dev/null 2>&1
  115.       ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
  116.     else
  117.       # If the link is to outside ${INPUT},
  118.       # treat this directory as if it actually contained the files.
  119. # This line used to have $dest instead of $x.
  120. # $dest seemed to be wrong for links found in subdirectories
  121. # of ${INPUT}.  Does this change break anything?
  122.       treetops="$treetops $x ${LIB}/$file"
  123.     fi
  124.       fi
  125.       cd $cwd
  126.     fi
  127.   done
  128. fi
  129.  
  130. set - $treetops
  131. while [ $# != 0 ]; do
  132.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  133.   echo "Finding header files in $1:"
  134.   cd ${INPUT}
  135.   cd $1
  136.   files=`find . -name '*.h' -type f -print`
  137.   echo 'Checking header files:'
  138.   for file in $files; do
  139.       if [ -r $file ]; then
  140.     cp $file $2/$file >/dev/null 2>&1 || echo "Can't copy $file"
  141.     chmod +w $2/$file
  142.     chmod a+r $2/$file
  143.  
  144. # The following have been removed from the sed command below
  145. # because it is more useful to leave these things in.
  146. # The only reason to remove them was for -pedantic,
  147. # which isn't much of a reason. -- rms.
  148. #      /^[     ]*#[     ]*ident/d
  149.  
  150. # This code makes Solaris SCSI fail, because it changes the
  151. # alignment within some critical structures.  See <sys/scsi/impl/commands.h>.
  152. #      s/u_char\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  153. # Disable these also, since they probably aren't safe either.
  154. #      s/u_short\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  155. #      s/ushort\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  156. #      s/evcm_t\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*[0-9][0-9]*\)/u_int\1/
  157. #      s/Pbyte\([     ][     ]*[a-zA-Z0-9_][a-zA-Z0-9_]*[     ]*:[     ]*SEQSIZ\)/unsigned int\1/
  158.  
  159. # The change of u_char, etc, to u_int
  160. # applies to bit fields.
  161.     sed -e '
  162.       s%^\([     ]*#[     ]*else\)[     ]*/[^*].*%\1%
  163.       s%^\([     ]*#[     ]*else\)[     ]*[^/     ].*%\1%
  164.       s%^\([     ]*#[     ]*endif\)[     ]*/[^*].*%\1%
  165.       s%^\([     ]*#[     ]*endif\)[     ]*[^/     ].*%\1%
  166.         s/#lint(on)/defined(lint)/g
  167.         s/#lint(off)/!defined(lint)/g
  168.         s/#machine(\([^)]*\))/defined(__\1__)/g
  169.         s/#system(\([^)]*\))/defined(__\1__)/g
  170.         s/#cpu(\([^)]*\))/defined(__\1__)/g
  171.       /#[a-z]*if.*[     (]m68k/        s/\([^_]\)m68k/\1__m68k__/g
  172.       /#[a-z]*if.*[     (]__i386\([^_]\)/    s/__i386/__i386__/g
  173.       /#[a-z]*if.*[     (]i386/        s/\([^_]\)i386/\1__i386__/g
  174.       /#[a-z]*if.*[     (!]__i860\([^_]\)/    s/__i860/__i860__/g
  175.       /#[a-z]*if.*[     (!]i860/        s/\([^_]\)i860/\1__i860__/g
  176.       /#[a-z]*if.*[     (]sparc/    s/\([^_]\)sparc/\1__sparc__/g
  177.       /#[a-z]*if.*[     (]mc68000/    s/\([^_]\)mc68000/\1__mc68000__/g
  178.       /#[a-z]*if.*[     (]vax/        s/\([^_]\)vax/\1__vax__/g
  179.       /#[a-z]*if.*[     (]sun/        s/\([^_]\)\(sun[a-z0-9]*\)\([^a-z0-9_]\)/\1__\2__\3/g
  180.       /#[a-z]*if.*[     (]sun/        s/\([^_]\)\(sun[a-z0-9]*\)$/\1__\2__/g
  181.       /#[a-z]*if.*[     (]ns32000/    s/\([^_]\)ns32000/\1__ns32000__/g
  182.       /#[a-z]*if.*[     (]pyr/        s/\([^_]\)pyr/\1__pyr__/g
  183.       /#[a-z]*if.*[     (]is68k/    s/\([^_]\)is68k/\1__is68k__/g
  184.       s/__STDC__[     ][     ]*==[     ][     ]*0/!defined (__STRICT_ANSI__)/g
  185.       s/__STDC__[     ][     ]*==[     ][     ]*1/defined (__STRICT_ANSI__)/g
  186.       s/__STDC__[     ][     ]*!=[     ][     ]*0/defined (__STRICT_ANSI__)/g
  187.       s/__STDC__ - 0 == 0/!defined (__STRICT_ANSI__)/g
  188.     ' $2/$file > $2/$file.sed
  189.     mv $2/$file.sed $2/$file
  190.     if cmp $file $2/$file >/dev/null 2>&1; then
  191.        rm $2/$file
  192.     else
  193.        echo Fixed $file
  194.     fi
  195.       fi
  196.   done
  197.   shift; shift
  198. done
  199.  
  200. # Install the proper definition of the three standard types in header files
  201. # that they come from.
  202. for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
  203.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  204.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  205.     chmod +w ${LIB}/$file 2>/dev/null
  206.     chmod a+r ${LIB}/$file 2>/dev/null
  207.   fi
  208.  
  209.   if [ -r ${LIB}/$file ]; then
  210.     echo Fixing size_t, ptrdiff_t and wchar_t in $file
  211.     sed \
  212.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]size_t/i\
  213. #ifndef __SIZE_TYPE__\
  214. #define __SIZE_TYPE__ long unsigned int\
  215. #endif
  216. ' \
  217.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]size_t/typedef __SIZE_TYPE__ size_t/' \
  218.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]ptrdiff_t/i\
  219. #ifndef __PTRDIFF_TYPE__\
  220. #define __PTRDIFF_TYPE__ long int\
  221. #endif
  222. ' \
  223.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
  224.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]wchar_t/i\
  225. #ifndef __WCHAR_TYPE__\
  226. #define __WCHAR_TYPE__ int\
  227. #endif
  228. ' \
  229.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
  230.       ${LIB}/$file > ${LIB}/${file}.sed
  231.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  232.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  233.       rm ${LIB}/$file
  234.     fi
  235.   fi
  236. done
  237.  
  238. # Fix first broken decl of getcwd present on some svr4 systems.
  239.  
  240. file=stdlib.h
  241. base=`basename $file`
  242. if [ -r ${LIB}/$file ]; then
  243.   file_to_fix=${LIB}/$file
  244. else
  245.   if [ -r ${INPUT}/$file ]; then
  246.     file_to_fix=${INPUT}/$file
  247.   else
  248.     file_to_fix=""
  249.   fi
  250. fi
  251. if [ \! -z "$file_to_fix" ]; then
  252.   echo Checking $file_to_fix
  253.   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix > /tmp/$base
  254.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  255.     true
  256.   else
  257.     echo Fixed $file_to_fix
  258.     rm -f ${LIB}/$file
  259.     cp /tmp/$base ${LIB}/$file
  260.     chmod a+r ${LIB}/$file
  261.   fi
  262.   rm -f /tmp/$base
  263. fi
  264.  
  265. # Fix second broken decl of getcwd present on some svr4 systems.  Also
  266. # fix the incorrect decl of profil present on some svr4 systems.
  267.  
  268. file=unistd.h
  269. base=`basename $file`
  270. if [ -r ${LIB}/$file ]; then
  271.   file_to_fix=${LIB}/$file
  272. else
  273.   if [ -r ${INPUT}/$file ]; then
  274.     file_to_fix=${INPUT}/$file
  275.   else
  276.     file_to_fix=""
  277.   fi
  278. fi
  279. if [ \! -z "$file_to_fix" ]; then
  280.   echo Checking $file_to_fix
  281.   sed -e 's/getcwd(char \*, int)/getcwd(char *, size_t)/' $file_to_fix \
  282.     | sed -e 's/profil(unsigned short \*, unsigned int, unsigned int, unsigned int)/profil(unsigned short *, size_t, int, unsigned)/' > /tmp/$base
  283.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  284.     true
  285.   else
  286.     echo Fixed $file_to_fix
  287.     rm -f ${LIB}/$file
  288.     cp /tmp/$base ${LIB}/$file
  289.     chmod a+r ${LIB}/$file
  290.   fi
  291.   rm -f /tmp/$base
  292. fi
  293.  
  294. # Fix the definition of NULL in <sys/param.h> so that it is conditional
  295. # and so that it is correct for both C and C++.
  296.  
  297. file=sys/param.h
  298. base=`basename $file`
  299. if [ -r ${LIB}/$file ]; then
  300.   file_to_fix=${LIB}/$file
  301. else
  302.   if [ -r ${INPUT}/$file ]; then
  303.     file_to_fix=${INPUT}/$file
  304.   else
  305.     file_to_fix=""
  306.   fi
  307. fi
  308. if [ \! -z "$file_to_fix" ]; then
  309.   echo Checking $file_to_fix
  310.   cp $file_to_fix /tmp/$base
  311.   chmod +w /tmp/$base
  312.   chmod a+r /tmp/$base
  313.   sed -e '/^#define[     ]*NULL[     ]*0$/c\
  314. #ifndef NULL\
  315. #ifdef __cplusplus\
  316. #define __NULL_TYPE\
  317. #else /* !defined(__cplusplus) */\
  318. #define __NULL_TYPE (void *)\
  319. #endif /* !defined(__cplusplus) */\
  320. #define NULL (__NULL_TYPE 0)\
  321. #endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
  322.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  323.     true
  324.   else
  325.     echo Fixed $file_to_fix
  326.     rm -f ${LIB}/$file
  327.     cp /tmp/$base.sed ${LIB}/$file
  328.     chmod a+r ${LIB}/$file
  329.   fi
  330.   rm -f /tmp/$base /tmp/$base.sed
  331. fi
  332.  
  333. # Likewise fix the definition of NULL in <stdio.h> so that it is conditional
  334. # and so that it is correct for both C and C++.
  335.  
  336. file=stdio.h
  337. base=`basename $file`
  338. if [ -r ${LIB}/$file ]; then
  339.   file_to_fix=${LIB}/$file
  340. else
  341.   if [ -r ${INPUT}/$file ]; then
  342.     file_to_fix=${INPUT}/$file
  343.   else
  344.     file_to_fix=""
  345.   fi
  346. fi
  347. if [ \! -z "$file_to_fix" ]; then
  348.   echo Checking $file_to_fix
  349.   cp $file_to_fix /tmp/$base
  350.   chmod +w /tmp/$base
  351.   sed -e '/^#define[     ]*NULL[     ]*0$/c\
  352. #ifdef __cplusplus\
  353. #define __NULL_TYPE\
  354. #else /* !defined(__cplusplus) */\
  355. #define __NULL_TYPE (void *)\
  356. #endif /* !defined(__cplusplus) */\
  357. #define NULL (__NULL_TYPE 0)' /tmp/$base > /tmp/$base.sed
  358.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  359.     true
  360.   else
  361.     echo Fixed $file_to_fix
  362.     rm -f ${LIB}/$file
  363.     cp /tmp/$base.sed ${LIB}/$file
  364.     chmod a+r ${LIB}/$file
  365.   fi
  366.   rm -f /tmp/$base /tmp/$base.sed
  367. fi
  368.  
  369. # Likewise fix the definition of NULL in <dbm.h> so that it is conditional
  370. # and so that it is correct for both C and C++.
  371.  
  372. file=dbm.h
  373. base=`basename $file`
  374. if [ -r ${LIB}/$file ]; then
  375.   file_to_fix=${LIB}/$file
  376. else
  377.   if [ -r ${INPUT}/$file ]; then
  378.     file_to_fix=${INPUT}/$file
  379.   else
  380.     file_to_fix=""
  381.   fi
  382. fi
  383. if [ \! -z "$file_to_fix" ]; then
  384.   echo Checking $file_to_fix
  385.   cp $file_to_fix /tmp/$base
  386.   chmod +w /tmp/$base
  387.   sed -e '/^#define[     ]*NULL[     ]*((char \*) 0)$/c\
  388. #ifndef NULL\
  389. #ifdef __cplusplus\
  390. #define __NULL_TYPE\
  391. #else /* !defined(__cplusplus) */\
  392. #define __NULL_TYPE (void *)\
  393. #endif /* !defined(__cplusplus) */\
  394. #define NULL (__NULL_TYPE 0)\
  395. #endif /* !defined(NULL) */' /tmp/$base > /tmp/$base.sed
  396.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  397.     true
  398.   else
  399.     echo Fixed $file_to_fix
  400.     rm -f ${LIB}/$file
  401.     cp /tmp/$base.sed ${LIB}/$file
  402.     chmod a+r ${LIB}/$file
  403.   fi
  404.   rm -f /tmp/$base /tmp/$base.sed
  405. fi
  406.  
  407. # Add a prototyped declaration of mmap to <sys/mman.h>.
  408.  
  409. file=sys/mman.h
  410. base=`basename $file`
  411. if [ -r ${LIB}/$file ]; then
  412.   file_to_fix=${LIB}/$file
  413. else
  414.   if [ -r ${INPUT}/$file ]; then
  415.     file_to_fix=${INPUT}/$file
  416.   else
  417.     file_to_fix=""
  418.   fi
  419. fi
  420. if [ \! -z "$file_to_fix" ]; then
  421.   echo Checking $file_to_fix
  422.   cp $file_to_fix /tmp/$base
  423.   chmod +w /tmp/$base
  424.   sed -e '/^extern caddr_t mmap();$/c\
  425. #ifdef __STDC__\
  426. extern caddr_t mmap (caddr_t, size_t, int, int, int, off_t);\
  427. #else /* !defined(__STDC__) */\
  428. extern caddr_t mmap ();\
  429. #endif /* !defined(__STDC__) */' /tmp/$base > /tmp/$base.sed
  430.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  431.     true
  432.   else
  433.     echo Fixed $file_to_fix
  434.     rm -f ${LIB}/$file
  435.     cp /tmp/$base.sed ${LIB}/$file
  436.     chmod a+r ${LIB}/$file
  437.   fi
  438.   rm -f /tmp/$base /tmp/$base.sed
  439. fi
  440.  
  441. # Fix declarations of `ftw' and `nftw' in <ftw.h>.  On some/most SVR4 systems
  442. # the file <ftw.h> contains extern declarations of these functions followed
  443. # by explicitly `static' definitions of these functions... and that's not
  444. # allowed according to ANSI C.  (Note however that on Solaris, this header
  445. # file glitch has been pre-fixed by Sun.  In the Solaris version of <ftw.h>
  446. # there are no static definitions of any function so we don't need to do
  447. # any of this stuff when on Solaris.
  448.  
  449. file=ftw.h
  450. base=`basename $file`
  451. if [ -r ${LIB}/$file ]; then
  452.   file_to_fix=${LIB}/$file
  453. else
  454.   if [ -r ${INPUT}/$file ]; then
  455.     file_to_fix=${INPUT}/$file
  456.   else
  457.     file_to_fix=""
  458.   fi
  459. fi
  460. if test -z "$file_to_fix" || grep 'define    ftw' $file_to_fix > /dev/null; then
  461. # Either we have no <ftw.h> file at all, or else we have the pre-fixed Solaris
  462. # one.  Either way, we don't have to do anything.
  463.   true
  464. else
  465.   echo Checking $file_to_fix
  466.   cp $file_to_fix /tmp/$base
  467.   chmod +w /tmp/$base
  468.   sed -e '/^extern int ftw(const/i\
  469. #if !defined(_STYPES)\
  470. static\
  471. #else\
  472. extern\
  473. #endif'\
  474.   -e 's/extern \(int ftw(const.*\)$/\1/' \
  475.   -e '/^extern int nftw/i\
  476. #if defined(_STYPES)\
  477. static\
  478. #else\
  479. extern\
  480. #endif'\
  481.   -e 's/extern \(int nftw.*\)$/\1/' \
  482.   -e '/^extern int ftw(),/c\
  483. #if !defined(_STYPES)\
  484. static\
  485. #else\
  486. extern\
  487. #endif\
  488.   int ftw();\
  489. #if defined(_STYPES)\
  490. static\
  491. #else\
  492. extern\
  493. #endif\
  494.   int nftw();' /tmp/$base > /tmp/$base.sed
  495.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  496.     true
  497.   else
  498.     echo Fixed $file_to_fix
  499.     rm -f ${LIB}/$file
  500.     cp /tmp/$base.sed ${LIB}/$file
  501.     chmod a+r ${LIB}/$file
  502.   fi
  503.   rm -f /tmp/$base /tmp/$base.sed
  504. fi
  505.  
  506. # Avoid the definition of the bool type in the Solaris 2.x curses.h when using
  507. # g++, since it's now an official type in the C++ language.
  508. file=curses.h
  509. base=`basename $file`
  510. if [ -r ${LIB}/$file ]; then
  511.   file_to_fix=${LIB}/$file
  512. else
  513.   if [ -r ${INPUT}/$file ]; then
  514.     file_to_fix=${INPUT}/$file
  515.   else
  516.     file_to_fix=""
  517.   fi
  518. fi
  519.  
  520. if [ \! -z "$file_to_fix" ]; then
  521.   echo Checking $file_to_fix
  522.   cp $file_to_fix /tmp/$base
  523.   chmod +w /tmp/$base
  524.   sed -e 's,^typedef[     ]char[     ]bool;$,#ifndef __cplusplus\
  525. typedef    char bool;\
  526. #endif /* !defined __cplusplus */,' /tmp/$base > /tmp/$base.sed
  527.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  528.     true
  529.   else
  530.     echo Fixed $file_to_fix
  531.     rm -f ${LIB}/$file
  532.     cp /tmp/$base.sed ${LIB}/$file
  533.     chmod a+r ${LIB}/$file
  534.   fi
  535.   rm -f /tmp/$base /tmp/$base.sed
  536. fi
  537.  
  538. # Add a `static' declaration of `getrnge' into <regexp.h>.
  539.  
  540. # Don't do this if there is already a `static void getrnge' declaration
  541. # present, since this would cause a redeclaration error.  Solaris 2.x has
  542. # such a declaration.
  543.  
  544. file=regexp.h
  545. base=`basename $file`
  546. if [ -r ${LIB}/$file ]; then
  547.   file_to_fix=${LIB}/$file
  548. else
  549.   if [ -r ${INPUT}/$file ]; then
  550.     file_to_fix=${INPUT}/$file
  551.   else
  552.     file_to_fix=""
  553.   fi
  554. fi
  555. if [ \! -z "$file_to_fix" ]; then
  556.   echo Checking $file_to_fix
  557.   if grep "static void getrnge" $file_to_fix > /dev/null; then
  558.     true
  559.   else
  560.     cp $file_to_fix /tmp/$base
  561.     chmod +w /tmp/$base
  562.     sed -e '/^static int[     ]*size;/c\
  563. static int    size ;\
  564. \
  565. static int getrnge ();' /tmp/$base > /tmp/$base.sed
  566.     if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  567.       true
  568.     else
  569.       echo Fixed $file_to_fix
  570.       rm -f ${LIB}/$file
  571.       cp /tmp/$base.sed ${LIB}/$file
  572.       chmod a+r ${LIB}/$file
  573.     fi
  574.   fi
  575.   rm -f /tmp/$base /tmp/$base.sed
  576. fi
  577.  
  578. # Disable apparent native compiler optimization cruft in SVR4.2 <string.h>
  579. # that is visible to any ANSI compiler using this include.  Simply
  580. # delete the lines that #define some string functions to internal forms.
  581.  
  582. file=string.h
  583. base=`basename $file`
  584. if [ -r ${LIB}/$file ]; then
  585.   file_to_fix=${LIB}/$file
  586. else
  587.   if [ -r ${INPUT}/$file ]; then
  588.     file_to_fix=${INPUT}/$file
  589.   else
  590.     file_to_fix=""
  591.   fi
  592. fi
  593. if [ \! -z "$file_to_fix" ]; then
  594.   echo Checking $file_to_fix
  595.   cp $file_to_fix /tmp/$base
  596.   chmod +w /tmp/$base
  597.   sed -e '/#define.*__std_hdr_/d' /tmp/$base > /tmp/$base.sed
  598.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  599.     true
  600.   else
  601.     echo Fixed $file_to_fix
  602.     rm -f ${LIB}/$file
  603.     cp /tmp/$base.sed ${LIB}/$file
  604.     chmod a+r ${LIB}/$file
  605.   fi
  606.   rm -f /tmp/$base /tmp/$base.sed
  607. fi
  608.  
  609. # Delete any #defines of `__i386' which may be present in <ieeefp.h>.  They
  610. # tend to conflict with the compiler's own definition of this symbol.  (We
  611. # will use the compiler's definition.)
  612. # Likewise __sparc, for Solaris, and __i860, and a few others
  613. # (guessing it is necessary for all of them).
  614.  
  615. file=ieeefp.h
  616. base=`basename $file`
  617. if [ -r ${LIB}/$file ]; then
  618.   file_to_fix=${LIB}/$file
  619. else
  620.   if [ -r ${INPUT}/$file ]; then
  621.     file_to_fix=${INPUT}/$file
  622.   else
  623.     file_to_fix=""
  624.   fi
  625. fi
  626. if [ \! -z "$file_to_fix" ]; then
  627.   echo Checking $file_to_fix
  628.   cp $file_to_fix /tmp/$base
  629.   chmod +w /tmp/$base
  630.   sed -e '/#define[     ]*__i386 /d' -e '/#define[     ]*__sparc /d' \
  631.       -e '/#define[     ]*__i860 /d' -e '/#define[     ]*__m88k /d' \
  632.       -e '/#define[     ]*__mips /d' -e '/#define[     ]*__m68k /d' \
  633.      /tmp/$base > /tmp/$base.sed
  634.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  635.     true
  636.   else
  637.     echo Fixed $file_to_fix 
  638.     rm -f ${LIB}/$file
  639.     cp /tmp/$base.sed ${LIB}/$file 
  640.     chmod a+r ${LIB}/$file
  641.   fi
  642.   rm -f /tmp/$base /tmp/$base.sed 
  643. fi 
  644.  
  645. # Add a #define of _SIGACTION_ into <sys/signal.h>.
  646. # Also fix types of SIG_DFL, SIG_ERR, SIG_IGN, and SIG_HOLD.
  647.  
  648. file=sys/signal.h
  649. base=`basename $file`
  650. if [ -r ${LIB}/$file ]; then
  651.   file_to_fix=${LIB}/$file
  652. else
  653.   if [ -r ${INPUT}/$file ]; then
  654.     file_to_fix=${INPUT}/$file
  655.   else
  656.     file_to_fix=""
  657.   fi
  658. fi
  659. if [ \! -z "$file_to_fix" ]; then
  660.   echo Checking $file_to_fix
  661.   cp $file_to_fix /tmp/$base
  662.   chmod +w /tmp/$base
  663.   sed -e '/^struct sigaction {/c\
  664. #define _SIGACTION_\
  665. struct  sigaction  {' \
  666.   -e '1,$s/(void *(\*)())/(void (*)(int))/' /tmp/$base > /tmp/$base.sed
  667.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  668.     true
  669.   else
  670.     echo Fixed $file_to_fix
  671.     rm -f ${LIB}/$file
  672.     cp /tmp/$base.sed ${LIB}/$file
  673.     chmod a+r ${LIB}/$file
  674.   fi
  675.   rm -f /tmp/$base /tmp/$base.sed
  676. fi
  677.  
  678. # Fix declarations of `makedev', `major', and `minor' in <sys/mkdev.h>.
  679.  
  680. file=sys/mkdev.h
  681. base=`basename $file`
  682. if [ -r ${LIB}/$file ]; then
  683.   file_to_fix=${LIB}/$file
  684. else
  685.   if [ -r ${INPUT}/$file ]; then
  686.     file_to_fix=${INPUT}/$file
  687.   else
  688.     file_to_fix=""
  689.   fi
  690. fi
  691. if [ \! -z "$file_to_fix" ]; then
  692.   echo Checking $file_to_fix
  693.   cp $file_to_fix /tmp/$base
  694.   chmod +w /tmp/$base
  695.   sed -e '/^dev_t makedev(const/c\
  696. static dev_t makedev(const major_t, const minor_t);' \
  697.   -e '/^dev_t makedev()/c\
  698. static dev_t makedev();' \
  699.   -e '/^major_t major(const/c\
  700. static major_t major(const dev_t);' \
  701.   -e '/^major_t major()/c\
  702. static major_t major();' \
  703.   -e '/^minor_t minor(const/c\
  704. static minor_t minor(const dev_t);' \
  705.   -e '/^minor_t minor()/c\
  706. static minor_t minor();' /tmp/$base > /tmp/$base.sed
  707.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  708.     true
  709.   else
  710.     echo Fixed $file_to_fix
  711.     rm -f ${LIB}/$file
  712.     cp /tmp/$base.sed ${LIB}/$file
  713.     chmod a+r ${LIB}/$file
  714.   fi
  715.   rm -f /tmp/$base /tmp/$base.sed
  716. fi
  717.  
  718. # Fix reference to NMSZ in <sys/adv.h>.
  719.  
  720. file=sys/adv.h
  721. base=`basename $file`
  722. if [ -r ${LIB}/$file ]; then
  723.   file_to_fix=${LIB}/$file
  724. else
  725.   if [ -r ${INPUT}/$file ]; then
  726.     file_to_fix=${INPUT}/$file
  727.   else
  728.     file_to_fix=""
  729.   fi
  730. fi
  731. if [ \! -z "$file_to_fix" ]; then
  732.   echo Checking $file_to_fix
  733.   sed 's/\[NMSZ\]/\[RFS_NMSZ\]/g' $file_to_fix > /tmp/$base
  734.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  735.     true
  736.   else
  737.     echo Fixed $file_to_fix
  738.     rm -f ${LIB}/$file
  739.     cp /tmp/$base ${LIB}/$file
  740.     chmod a+r ${LIB}/$file
  741.   fi
  742.   rm -f /tmp/$base
  743. fi
  744.  
  745. # Fix reference to NC_NPI_RAW in <sys/netcspace.h>.  Also fix types of
  746. # array initializers.
  747.  
  748. file=sys/netcspace.h
  749. base=`basename $file`
  750. if [ -r ${LIB}/$file ]; then
  751.   file_to_fix=${LIB}/$file
  752. else
  753.   if [ -r ${INPUT}/$file ]; then
  754.     file_to_fix=${INPUT}/$file
  755.   else
  756.     file_to_fix=""
  757.   fi
  758. fi
  759. if [ \! -z "$file_to_fix" ]; then
  760.   echo Checking $file_to_fix
  761.   sed 's/NC_NPI_RAW/NC_TPI_RAW/g' $file_to_fix \
  762.     | sed 's/NC_/(unsigned long) NC_/' > /tmp/$base
  763.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  764.     true
  765.   else
  766.     echo Fixed $file_to_fix
  767.     rm -f ${LIB}/$file
  768.     cp /tmp/$base ${LIB}/$file
  769.     chmod a+r ${LIB}/$file
  770.   fi
  771.   rm -f /tmp/$base
  772. fi
  773.  
  774. # Conditionalize all of <fs/rfs/rf_cache.h> on _KERNEL being defined.
  775.  
  776. file=fs/rfs/rf_cache.h
  777. base=`basename $file`
  778. if [ -r ${LIB}/$file ]; then
  779.   file_to_fix=${LIB}/$file
  780. else
  781.   if [ -r ${INPUT}/$file ]; then
  782.     file_to_fix=${INPUT}/$file
  783.   else
  784.     file_to_fix=""
  785.   fi
  786. fi
  787. if [ \! -z "$file_to_fix" ]; then
  788.   echo Checking $file_to_fix
  789.   if grep _KERNEL $file_to_fix > /dev/null; then
  790.     true
  791.   else
  792.     echo '#ifdef _KERNEL' > /tmp/$base
  793.     cat $file_to_fix >> /tmp/$base
  794.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  795.     echo Fixed $file_to_fix
  796.     rm -f ${LIB}/$file
  797.     cp /tmp/$base ${LIB}/$file
  798.     chmod a+r ${LIB}/$file
  799.     rm -f /tmp/$base
  800.   fi
  801. fi
  802.  
  803. # Conditionalize all of <sys/erec.h> on _KERNEL being defined.
  804.  
  805. file=sys/erec.h
  806. base=`basename $file`
  807. if [ -r ${LIB}/$file ]; then
  808.   file_to_fix=${LIB}/$file
  809. else
  810.   if [ -r ${INPUT}/$file ]; then
  811.     file_to_fix=${INPUT}/$file
  812.   else
  813.     file_to_fix=""
  814.   fi
  815. fi
  816. if [ \! -z "$file_to_fix" ]; then
  817.   echo Checking $file_to_fix
  818.   if grep _KERNEL $file_to_fix > /dev/null; then
  819.     true
  820.   else
  821.     echo '#ifdef _KERNEL' > /tmp/$base
  822.     cat $file_to_fix >> /tmp/$base
  823.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  824.     echo Fixed $file_to_fix
  825.     rm -f ${LIB}/$file
  826.     cp /tmp/$base ${LIB}/$file
  827.     chmod a+r ${LIB}/$file
  828.     rm -f /tmp/$base
  829.   fi
  830. fi
  831.  
  832. # Conditionalize all of <sys/err.h> on _KERNEL being defined.
  833.  
  834. file=sys/err.h
  835. base=`basename $file`
  836. if [ -r ${LIB}/$file ]; then
  837.   file_to_fix=${LIB}/$file
  838. else
  839.   if [ -r ${INPUT}/$file ]; then
  840.     file_to_fix=${INPUT}/$file
  841.   else
  842.     file_to_fix=""
  843.   fi
  844. fi
  845. if [ \! -z "$file_to_fix" ]; then
  846.   echo Checking $file_to_fix
  847.   if grep _KERNEL $file_to_fix > /dev/null; then
  848.     true
  849.   else
  850.     echo '#ifdef _KERNEL' > /tmp/$base
  851.     cat $file_to_fix >> /tmp/$base
  852.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  853.     echo Fixed $file_to_fix
  854.     rm -f ${LIB}/$file
  855.     cp /tmp/$base ${LIB}/$file
  856.     chmod a+r ${LIB}/$file
  857.     rm -f /tmp/$base
  858.   fi
  859. fi
  860.  
  861. # Conditionalize all of <sys/char.h> on _KERNEL being defined.
  862.  
  863. file=sys/char.h
  864. base=`basename $file`
  865. if [ -r ${LIB}/$file ]; then
  866.   file_to_fix=${LIB}/$file
  867. else
  868.   if [ -r ${INPUT}/$file ]; then
  869.     file_to_fix=${INPUT}/$file
  870.   else
  871.     file_to_fix=""
  872.   fi
  873. fi
  874. if [ \! -z "$file_to_fix" ]; then
  875.   echo Checking $file_to_fix
  876.   if grep _KERNEL $file_to_fix > /dev/null; then
  877.     true
  878.   else
  879.     echo '#ifdef _KERNEL' > /tmp/$base
  880.     cat $file_to_fix >> /tmp/$base
  881.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  882.     echo Fixed $file_to_fix
  883.     rm -f ${LIB}/$file
  884.     cp /tmp/$base ${LIB}/$file
  885.     chmod a+r ${LIB}/$file
  886.     rm -f /tmp/$base
  887.   fi
  888. fi
  889.  
  890. # Conditionalize all of <sys/getpages.h> on _KERNEL being defined.
  891.  
  892. file=sys/getpages.h
  893. base=`basename $file`
  894. if [ -r ${LIB}/$file ]; then
  895.   file_to_fix=${LIB}/$file
  896. else
  897.   if [ -r ${INPUT}/$file ]; then
  898.     file_to_fix=${INPUT}/$file
  899.   else
  900.     file_to_fix=""
  901.   fi
  902. fi
  903. if [ \! -z "$file_to_fix" ]; then
  904.   echo Checking $file_to_fix
  905.   if grep _KERNEL $file_to_fix > /dev/null; then
  906.     true
  907.   else
  908.     echo '#ifdef _KERNEL' > /tmp/$base
  909.     cat $file_to_fix >> /tmp/$base
  910.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  911.     echo Fixed $file_to_fix
  912.     rm -f ${LIB}/$file
  913.     cp /tmp/$base ${LIB}/$file
  914.     chmod a+r ${LIB}/$file
  915.     rm -f /tmp/$base
  916.   fi
  917. fi
  918.  
  919. # Conditionalize all of <sys/map.h> on _KERNEL being defined.
  920.  
  921. file=sys/map.h
  922. base=`basename $file`
  923. if [ -r ${LIB}/$file ]; then
  924.   file_to_fix=${LIB}/$file
  925. else
  926.   if [ -r ${INPUT}/$file ]; then
  927.     file_to_fix=${INPUT}/$file
  928.   else
  929.     file_to_fix=""
  930.   fi
  931. fi
  932. if [ \! -z "$file_to_fix" ]; then
  933.   echo Checking $file_to_fix
  934.   if grep _KERNEL $file_to_fix > /dev/null; then
  935.     true
  936.   else
  937.     echo '#ifdef _KERNEL' > /tmp/$base
  938.     cat $file_to_fix >> /tmp/$base
  939.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  940.     echo Fixed $file_to_fix
  941.     rm -f ${LIB}/$file
  942.     cp /tmp/$base ${LIB}/$file
  943.     chmod a+r ${LIB}/$file
  944.     rm -f /tmp/$base
  945.   fi
  946. fi
  947.  
  948. # Conditionalize all of <sys/cmn_err.h> on _KERNEL being defined.
  949.  
  950. file=sys/cmn_err.h
  951. base=`basename $file`
  952. if [ -r ${LIB}/$file ]; then
  953.   file_to_fix=${LIB}/$file
  954. else
  955.   if [ -r ${INPUT}/$file ]; then
  956.     file_to_fix=${INPUT}/$file
  957.   else
  958.     file_to_fix=""
  959.   fi
  960. fi
  961. if [ \! -z "$file_to_fix" ]; then
  962.   echo Checking $file_to_fix
  963.   if grep _KERNEL $file_to_fix > /dev/null; then
  964.     true
  965.   else
  966.     echo '#ifdef _KERNEL' > /tmp/$base
  967.     cat $file_to_fix >> /tmp/$base
  968.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  969.     echo Fixed $file_to_fix
  970.     rm -f ${LIB}/$file
  971.     cp /tmp/$base ${LIB}/$file
  972.     chmod a+r ${LIB}/$file
  973.     rm -f /tmp/$base
  974.   fi
  975. fi
  976.  
  977. # Conditionalize all of <sys/kdebugger.h> on _KERNEL being defined.
  978.  
  979. file=sys/kdebugger.h
  980. base=`basename $file`
  981. if [ -r ${LIB}/$file ]; then
  982.   file_to_fix=${LIB}/$file
  983. else
  984.   if [ -r ${INPUT}/$file ]; then
  985.     file_to_fix=${INPUT}/$file
  986.   else
  987.     file_to_fix=""
  988.   fi
  989. fi
  990. if [ \! -z "$file_to_fix" ]; then
  991.   echo Checking $file_to_fix
  992.   if grep _KERNEL $file_to_fix > /dev/null; then
  993.     true
  994.   else
  995.     echo '#ifdef _KERNEL' > /tmp/$base
  996.     cat $file_to_fix >> /tmp/$base
  997.     echo '#endif /* defined(_KERNEL) */' >> /tmp/$base
  998.     echo Fixed $file_to_fix
  999.     rm -f ${LIB}/$file
  1000.     cp /tmp/$base ${LIB}/$file
  1001.     chmod a+r ${LIB}/$file
  1002.     rm -f /tmp/$base
  1003.   fi
  1004. fi
  1005.  
  1006. # Conditionalize some of <netinet/in.h> on _KERNEL being defined.
  1007.  
  1008. file=netinet/in.h
  1009. base=`basename $file`
  1010. if [ -r ${LIB}/$file ]; then
  1011.   file_to_fix=${LIB}/$file
  1012. else
  1013.   if [ -r ${INPUT}/$file ]; then
  1014.     file_to_fix=${INPUT}/$file
  1015.   else
  1016.     file_to_fix=""
  1017.   fi
  1018. fi
  1019. if [ \! -z "$file_to_fix" ]; then
  1020.   echo Checking $file_to_fix
  1021.   if grep _KERNEL $file_to_fix > /dev/null; then
  1022.     true
  1023.   else
  1024.     sed -e '/#ifdef INKERNEL/i\
  1025. #ifdef _KERNEL' \
  1026.     -e '/#endif[     ]*\/\* INKERNEL \*\//a\
  1027. #endif /* _KERNEL */' \
  1028.     $file_to_fix > ${LIB}/${file}.sed
  1029.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1030.     echo Fixed $file_to_fix
  1031.   fi
  1032. fi
  1033.  
  1034. # Conditionalize some of <sys/endian.h> on __GNUC__ and __GNUG__.
  1035.  
  1036. file=sys/endian.h
  1037. base=`basename $file`
  1038. if [ -r ${LIB}/$file ]; then
  1039.   file_to_fix=${LIB}/$file
  1040. else
  1041.   if [ -r ${INPUT}/$file ]; then
  1042.     file_to_fix=${INPUT}/$file
  1043.   else
  1044.     file_to_fix=""
  1045.   fi
  1046. fi
  1047. if [ \! -z "$file_to_fix" ]; then
  1048.   echo Checking $file_to_fix
  1049.   if grep __GNUC__ $file_to_fix > /dev/null; then
  1050.     true
  1051.   else
  1052.     sed -e '/#    ifdef    __STDC__/i\
  1053. #   if !defined (__GNUC__) && !defined (__GNUG__)' \
  1054.     -e '/#        include    <sys\/byteorder.h>/s/        /   /'\
  1055.     -e '/#   include    <sys\/byteorder.h>/i\
  1056. #   endif /* !defined (__GNUC__) && !defined (__GNUG__) */'\
  1057.     $file_to_fix > ${LIB}/${file}.sed
  1058.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1059.     echo Fixed $file_to_fix
  1060.   fi
  1061. fi
  1062.  
  1063. # Commented out because tmcconne@sedona.intel.com says we don't clearly need it
  1064. # and the text in types.h is not erroneous.
  1065. ## In sys/types.h, don't name the enum for booleans.
  1066. #
  1067. #file=sys/types.h
  1068. #base=`basename $file`
  1069. #if [ -r ${LIB}/$file ]; then
  1070. #  file_to_fix=${LIB}/$file
  1071. #else
  1072. #  if [ -r ${INPUT}/$file ]; then
  1073. #    file_to_fix=${INPUT}/$file
  1074. #  else
  1075. #    file_to_fix=""
  1076. #  fi
  1077. #fi
  1078. #if [ \! -z "$file_to_fix" ]; then
  1079. #  echo Checking $file_to_fix
  1080. #  if grep "enum boolean" $file_to_fix > /dev/null; then
  1081. #    sed -e 's/enum boolean/enum/' ${LIB}/$file > ${LIB}/${file}.sed
  1082. #    rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1083. #    echo Fixed $file_to_fix
  1084. #  else
  1085. #    true
  1086. #  fi
  1087. #fi
  1088.  
  1089. # Remove useless extern keyword from struct forward declarations in
  1090. # <sys/stream.h> and <sys/strsubr.h>
  1091.  
  1092. file=sys/stream.h
  1093. base=`basename $file`
  1094. if [ -r ${LIB}/$file ]; then
  1095.   file_to_fix=${LIB}/$file
  1096. else
  1097.   if [ -r ${INPUT}/$file ]; then
  1098.     file_to_fix=${INPUT}/$file
  1099.   else
  1100.     file_to_fix=""
  1101.   fi
  1102. fi
  1103. if [ \! -z "$file_to_fix" ]; then
  1104.   echo Checking $file_to_fix
  1105.   sed -e '
  1106.     s/extern struct stdata;/struct stdata;/g
  1107.     s/extern struct strevent;/struct strevent;/g
  1108.   ' $file_to_fix > /tmp/$base 
  1109.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  1110.     true
  1111.   else
  1112.     echo Fixed $file_to_fix
  1113.     rm -f ${LIB}/$file
  1114.     cp /tmp/$base ${LIB}/$file
  1115.     chmod a+r ${LIB}/$file
  1116.   fi
  1117.   rm -f /tmp/$base
  1118. fi
  1119.  
  1120. file=sys/strsubr.h
  1121. base=`basename $file`
  1122. if [ -r ${LIB}/$file ]; then
  1123.   file_to_fix=${LIB}/$file
  1124. else
  1125.   if [ -r ${INPUT}/$file ]; then
  1126.     file_to_fix=${INPUT}/$file
  1127.   else
  1128.     file_to_fix=""
  1129.   fi
  1130. fi
  1131. if [ \! -z "$file_to_fix" ]; then
  1132.   echo Checking $file_to_fix
  1133.   sed -e '
  1134.     s/extern struct strbuf;/struct strbuf;/g
  1135.     s/extern struct uio;/struct uio;/g
  1136.     s/extern struct thread;/struct thread;/g
  1137.     s/extern struct proc;/struct proc;/g
  1138.   ' $file_to_fix > /tmp/$base 
  1139.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  1140.     true
  1141.   else
  1142.     echo Fixed $file_to_fix
  1143.     rm -f ${LIB}/$file
  1144.     cp /tmp/$base ${LIB}/$file
  1145.     chmod a+r ${LIB}/$file
  1146.   fi
  1147.   rm -f /tmp/$base
  1148. fi
  1149.  
  1150. # Put storage class at start of decl, to avoid warning.
  1151. file=rpc/types.h
  1152. base=`basename $file`
  1153. if [ -r ${LIB}/$file ]; then
  1154.   file_to_fix=${LIB}/$file
  1155. else
  1156.   if [ -r ${INPUT}/$file ]; then
  1157.     file_to_fix=${INPUT}/$file
  1158.   else
  1159.     file_to_fix=""
  1160.   fi
  1161. fi
  1162. if [ \! -z "$file_to_fix" ]; then
  1163.   echo Checking $file_to_fix
  1164.   sed -e '
  1165.     s/const extern/extern const/g
  1166.   ' $file_to_fix > /tmp/$base 
  1167.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  1168.     true
  1169.   else
  1170.     echo Fixed $file_to_fix
  1171.     rm -f ${LIB}/$file
  1172.     cp /tmp/$base ${LIB}/$file
  1173.     chmod a+r ${LIB}/$file
  1174.   fi
  1175.   rm -f /tmp/$base
  1176. fi
  1177.  
  1178. # Convert functions to prototype form, and fix arg names in <sys/stat.h>.
  1179.  
  1180. file=sys/stat.h
  1181. base=`basename $file`
  1182. if [ -r ${LIB}/$file ]; then
  1183.   file_to_fix=${LIB}/$file
  1184. else
  1185.   if [ -r ${INPUT}/$file ]; then
  1186.     file_to_fix=${INPUT}/$file
  1187.   else
  1188.     file_to_fix=""
  1189.   fi
  1190. fi
  1191. if [ \! -z "$file_to_fix" ]; then
  1192.   echo Checking $file_to_fix
  1193.   cp $file_to_fix /tmp/$base
  1194.   chmod +w /tmp/$base
  1195.   sed -e '/^stat([     ]*[^c]/{
  1196. N
  1197. N
  1198. s/(.*)\n/( /
  1199. s/;\n/, /
  1200. s/;$/)/
  1201. }' \
  1202.   -e '/^lstat([     ]*[^c]/{
  1203. N
  1204. N
  1205. s/(.*)\n/( /
  1206. s/;\n/, /
  1207. s/;$/)/
  1208. }' \
  1209.   -e '/^fstat([     ]*[^i]/{
  1210. N
  1211. N
  1212. s/(.*)\n/( /
  1213. s/;\n/, /
  1214. s/;$/)/
  1215. }' \
  1216.   -e '/^mknod([     ]*[^c]/{
  1217. N
  1218. N
  1219. N
  1220. s/(.*)\n/( /
  1221. s/;\n/, /g
  1222. s/;$/)/
  1223. }' \
  1224.   -e '1,$s/\([^A-Za-z]\)path\([^A-Za-z]\)/\1__path\2/g' \
  1225.   -e '1,$s/\([^A-Za-z]\)buf\([^A-Za-z]\)/\1__buf\2/g' \
  1226.   -e '1,$s/\([^A-Za-z]\)fd\([^A-Za-z]\)/\1__fd\2/g' \
  1227.   -e '1,$s/ret\([^u]\)/__ret\1/g' \
  1228.   -e '1,$s/\([^_]\)mode\([^_]\)/\1__mode\2/g' \
  1229.   -e '1,$s/\([^_r]\)dev\([^_]\)/\1__dev\2/g' /tmp/$base > /tmp/$base.sed
  1230.   if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then \
  1231.     true
  1232.   else
  1233.     echo Fixed $file_to_fix
  1234.     rm -f ${LIB}/$file
  1235.     cp /tmp/$base.sed ${LIB}/$file
  1236.     chmod a+r ${LIB}/$file
  1237.   fi
  1238.   rm -f /tmp/$base /tmp/$base.sed
  1239. fi
  1240.  
  1241. # Sony NEWSOS 5.0 does not support the complete ANSI C standard.
  1242.  
  1243. if [ -x /bin/sony ]; then
  1244.   if /bin/sony; then
  1245.  
  1246.     # Change <stdio.h> to not define __filbuf, __flsbuf, and __iob
  1247.  
  1248.     file=stdio.h
  1249.     base=`basename $file`
  1250.     if [ -r ${LIB}/$file ]; then
  1251.       file_to_fix=${LIB}/$file
  1252.     else
  1253.       if [ -r ${INPUT}/$file ]; then
  1254.         file_to_fix=${INPUT}/$file
  1255.       else
  1256.         file_to_fix=""
  1257.       fi
  1258.     fi
  1259.     if [ \! -z "$file_to_fix" ]; then
  1260.       echo Checking $file_to_fix
  1261.       cp $file_to_fix /tmp/$base
  1262.       chmod +w /tmp/$base
  1263.       sed -e '
  1264.         s/__filbuf/_filbuf/g
  1265.         s/__flsbuf/_flsbuf/g
  1266.         s/__iob/_iob/g
  1267.       ' /tmp/$base > /tmp/$base.sed
  1268.       mv /tmp/$base.sed /tmp/$base
  1269.       if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
  1270.         true
  1271.       else
  1272.         echo Fixed $file_to_fix
  1273.         rm -f ${LIB}/$file
  1274.         cp /tmp/$base ${LIB}/$file
  1275.         chmod a+r ${LIB}/$file
  1276.       fi
  1277.       rm -f /tmp/$base
  1278.     fi
  1279.  
  1280.     # Change <ctype.h> to not define __ctype
  1281.  
  1282.     file=ctype.h
  1283.     base=`basename $file`
  1284.     if [ -r ${LIB}/$file ]; then
  1285.       file_to_fix=${LIB}/$file
  1286.     else
  1287.       if [ -r ${INPUT}/$file ]; then
  1288.         file_to_fix=${INPUT}/$file
  1289.       else
  1290.         file_to_fix=""
  1291.       fi
  1292.     fi
  1293.     if [ \! -z "$file_to_fix" ]; then
  1294.       echo Checking $file_to_fix
  1295.       cp $file_to_fix /tmp/$base
  1296.       chmod +w /tmp/$base
  1297.       sed -e '
  1298.         s/__ctype/_ctype/g
  1299.       ' /tmp/$base > /tmp/$base.sed
  1300.       mv /tmp/$base.sed /tmp/$base
  1301.       if cmp $file_to_fix /tmp/$base.sed >/dev/null 2>&1; then
  1302.         true
  1303.       else
  1304.         echo Fixed $file_to_fix
  1305.         rm -f ${LIB}/$file
  1306.         cp /tmp/$base ${LIB}/$file
  1307.         chmod a+r ${LIB}/$file
  1308.       fi
  1309.       rm -f /tmp/$base
  1310.     fi
  1311.   fi
  1312. fi
  1313.  
  1314. # In limits.h, put #ifndefs around things that are supposed to be defined
  1315. # in float.h to avoid redefinition errors if float.h is included first.
  1316. # Solaris 2.1 has this problem.
  1317.  
  1318. file=limits.h
  1319. base=`basename $file`
  1320. if [ -r ${LIB}/$file ]; then
  1321.   file_to_fix=${LIB}/$file
  1322. else
  1323.   if [ -r ${INPUT}/$file ]; then
  1324.     file_to_fix=${INPUT}/$file
  1325.   else
  1326.     file_to_fix=""
  1327.   fi
  1328. fi
  1329. if [ \! -z "$file_to_fix" ]; then
  1330.   echo Checking $file_to_fix
  1331.   sed -e '/[     ]FLT_MIN[     ]/i\
  1332. #ifndef FLT_MIN'\
  1333.       -e '/[     ]FLT_MIN[     ]/a\
  1334. #endif'\
  1335.       -e '/[     ]FLT_MAX[     ]/i\
  1336. #ifndef FLT_MAX'\
  1337.       -e '/[     ]FLT_MAX[     ]/a\
  1338. #endif'\
  1339.       -e '/[     ]FLT_DIG[     ]/i\
  1340. #ifndef FLT_DIG'\
  1341.       -e '/[     ]FLT_DIG[     ]/a\
  1342. #endif'\
  1343.       -e '/[     ]DBL_MIN[     ]/i\
  1344. #ifndef DBL_MIN'\
  1345.       -e '/[     ]DBL_MIN[     ]/a\
  1346. #endif'\
  1347.       -e '/[     ]DBL_MAX[     ]/i\
  1348. #ifndef DBL_MAX'\
  1349.       -e '/[     ]DBL_MAX[     ]/a\
  1350. #endif'\
  1351.       -e '/[     ]DBL_DIG[     ]/i\
  1352. #ifndef DBL_DIG'\
  1353.       -e '/[     ]DBL_DIG[     ]/a\
  1354. #endif' $file_to_fix > /tmp/$base
  1355.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  1356.     true
  1357.   else
  1358.     echo Fixed $file_to_fix
  1359.     rm -f ${LIB}/$file
  1360.     cp /tmp/$base ${LIB}/$file
  1361.     chmod a+r ${LIB}/$file
  1362.   fi
  1363.   rm -f /tmp/$base
  1364. fi
  1365.  
  1366. # Completely replace <sys/varargs.h> with a file that includes gcc's
  1367. # stdarg.h or varargs.h files as appropriate.
  1368.  
  1369. file=sys/varargs.h
  1370. if [ -r ${INPUT}/$file ]; then
  1371.   echo Replacing $file
  1372.   cat > ${LIB}/$file << EOF
  1373. /* This file was generated by fixincludes.  */
  1374. #ifndef _SYS_VARARGS_H
  1375. #define _SYS_VARARGS_H
  1376.  
  1377. #ifdef __STDC__
  1378. #include <stdarg.h>
  1379. #else
  1380. #include <varargs.h>
  1381. #endif
  1382.  
  1383. #endif  /* _SYS_VARARGS_H */
  1384. EOF
  1385.   chmod a+r ${LIB}/$file
  1386. fi
  1387.  
  1388. # In math.h, put #ifndefs around things that might be defined in a gcc
  1389. # specific math-*.h file.
  1390.  
  1391. file=math.h
  1392. base=`basename $file`
  1393. if [ -r ${LIB}/$file ]; then
  1394.   file_to_fix=${LIB}/$file
  1395. else
  1396.   if [ -r ${INPUT}/$file ]; then
  1397.     file_to_fix=${INPUT}/$file
  1398.   else
  1399.     file_to_fix=""
  1400.   fi
  1401. fi
  1402. if [ \! -z "$file_to_fix" ]; then
  1403.   echo Checking $file_to_fix
  1404.   sed -e '/define[     ]HUGE_VAL[     ]/i\
  1405. #ifndef HUGE_VAL'\
  1406.       -e '/define[     ]HUGE_VAL[     ]/a\
  1407. #endif' $file_to_fix > /tmp/$base
  1408.   if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  1409.     true
  1410.   else
  1411.     echo Fixed $file_to_fix
  1412.     rm -f ${LIB}/$file
  1413.     cp /tmp/$base ${LIB}/$file
  1414.     chmod a+r ${LIB}/$file
  1415.   fi
  1416.   rm -f /tmp/$base
  1417. fi
  1418.  
  1419. # Solaris math.h and floatingpoint.h define __P without protection,
  1420. # which conflicts with the fixproto definition.  The fixproto
  1421. # definition and the Solaris definition are used the same way.
  1422. for file in math.h floatingpoint.h; do
  1423.   base=`basename $file`
  1424.   if [ -r ${LIB}/$file ]; then
  1425.     file_to_fix=${LIB}/$file
  1426.   else
  1427.     if [ -r ${INPUT}/$file ]; then
  1428.       file_to_fix=${INPUT}/$file
  1429.     else
  1430.       file_to_fix=""
  1431.     fi
  1432.   fi
  1433.   if [ \! -z "$file_to_fix" ]; then
  1434.     echo Checking $file_to_fix
  1435.     sed -e '/^#define[     ]*__P/i\
  1436. #ifndef __P'\
  1437.         -e '/^#define[     ]*__P/a\
  1438. #endif' $file_to_fix > /tmp/$base
  1439.     if cmp $file_to_fix /tmp/$base >/dev/null 2>&1; then \
  1440.       true
  1441.     else
  1442.       echo Fixed $file_to_fix
  1443.       rm -f ${LIB}/$file
  1444.       cp /tmp/$base ${LIB}/$file
  1445.       chmod a+r ${LIB}/$file
  1446.     fi
  1447.    rm -f /tmp/$base
  1448.   fi
  1449. done
  1450.  
  1451. echo 'Removing unneeded directories:'
  1452. cd $LIB
  1453. files=`find . -type d -print | sort -r`
  1454. for file in $files; do
  1455.   rmdir $LIB/$file > /dev/null 2>&1
  1456. done
  1457.  
  1458. if $LINKS; then
  1459.   echo 'Making internal symbolic non-directory links'
  1460.   cd ${INPUT}
  1461.   files=`find . -type l -print`
  1462.   for file in $files; do
  1463.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  1464.     if expr "$dest" : '[^/].*' > /dev/null; then    
  1465.       target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  1466.       if [ -f $target ]; then
  1467.         ln -s $dest ${LIB}/$file >/dev/null 2>&1
  1468.       fi
  1469.     fi
  1470.   done
  1471. fi
  1472.  
  1473. cd ${ORIG_DIR}
  1474.  
  1475. echo 'Replacing <sys/byteorder.h>'
  1476. if [ \! -d $LIB/sys ]; then
  1477.   mkdir $LIB/sys
  1478. fi
  1479. rm -f ${LIB}/sys/byteorder.h
  1480. cat <<'__EOF__' >${LIB}/sys/byteorder.h
  1481. #ifndef _SYS_BYTEORDER_H
  1482. #define _SYS_BYTEORDER_H
  1483.  
  1484. /* Functions to convert `short' and `long' quantities from host byte order
  1485.    to (internet) network byte order (i.e. big-endian).
  1486.  
  1487.    Written by Ron Guilmette (rfg@ncd.com).
  1488.  
  1489.    This isn't actually used by GCC.  It is installed by fixinc.svr4.
  1490.  
  1491.    For big-endian machines these functions are essentially no-ops.
  1492.  
  1493.    For little-endian machines, we define the functions using specialized
  1494.    asm sequences in cases where doing so yields better code (e.g. i386).  */
  1495.  
  1496. #if !defined (__GNUC__) && !defined (__GNUG__)
  1497. #error You lose!  This file is only useful with GNU compilers.
  1498. #endif
  1499.  
  1500. #ifndef __BYTE_ORDER__
  1501. /* Byte order defines.  These are as defined on UnixWare 1.1, but with
  1502.    double underscores added at the front and back.  */
  1503. #define __LITTLE_ENDIAN__   1234
  1504. #define __BIG_ENDIAN__      4321
  1505. #define __PDP_ENDIAN__      3412
  1506. #endif
  1507.  
  1508. #ifdef __STDC__
  1509. extern __inline__ unsigned long htonl (unsigned long);
  1510. extern __inline__ unsigned short htons (unsigned int);
  1511. extern __inline__ unsigned long ntohl (unsigned long);
  1512. extern __inline__ unsigned short ntohs (unsigned int);
  1513. #endif /* defined (__STDC__) */
  1514.  
  1515. #if defined (__i386__)
  1516.  
  1517. #ifndef __BYTE_ORDER__
  1518. #define __BYTE_ORDER__ __LITTLE_ENDIAN__
  1519. #endif
  1520.  
  1521. /* Convert a host long to a network long.  */
  1522.  
  1523. /* We must use a new-style function definition, so that this will also
  1524.    be valid for C++.  */
  1525. extern __inline__ unsigned long
  1526. htonl (unsigned long __arg)
  1527. {
  1528.   register unsigned long __result;
  1529.  
  1530.   __asm__ ("xchg%B0 %b0,%h0\n\
  1531.     ror%L0 $16,%0\n\
  1532.     xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
  1533.   return __result;
  1534. }
  1535.  
  1536. /* Convert a host short to a network short.  */
  1537.  
  1538. extern __inline__ unsigned short
  1539. htons (unsigned int __arg)
  1540. {
  1541.   register unsigned short __result;
  1542.  
  1543.   __asm__ ("xchg%B0 %b0,%h0" : "=q" (__result) : "0" (__arg));
  1544.   return __result;
  1545. }
  1546.  
  1547. #elif ((defined (__i860__) && !defined (__i860_big_endian__))    \
  1548.        || defined (__ns32k__) || defined (__vax__)        \
  1549.        || defined (__spur__) || defined (__arm__))
  1550.  
  1551. #ifndef __BYTE_ORDER__
  1552. #define __BYTE_ORDER__ __LITTLE_ENDIAN__
  1553. #endif
  1554.  
  1555. /* For other little-endian machines, using C code is just as efficient as
  1556.    using assembly code.  */
  1557.  
  1558. /* Convert a host long to a network long.  */
  1559.  
  1560. extern __inline__ unsigned long
  1561. htonl (unsigned long __arg)
  1562. {
  1563.   register unsigned long __result;
  1564.  
  1565.   __result = (__arg >> 24) & 0x000000ff;
  1566.   __result |= (__arg >> 8) & 0x0000ff00;
  1567.   __result |= (__arg << 8) & 0x00ff0000;
  1568.   __result |= (__arg << 24) & 0xff000000;
  1569.   return __result;
  1570. }
  1571.  
  1572. /* Convert a host short to a network short.  */
  1573.  
  1574. extern __inline__ unsigned short
  1575. htons (unsigned int __arg)
  1576. {
  1577.   register unsigned short __result;
  1578.  
  1579.   __result = (__arg << 8) & 0xff00;
  1580.   __result |= (__arg >> 8) & 0x00ff;
  1581.   return __result;
  1582. }
  1583.  
  1584. #else /* must be a big-endian machine */
  1585.  
  1586. #ifndef __BYTE_ORDER__
  1587. #define __BYTE_ORDER__ __BIG_ENDIAN__
  1588. #endif
  1589.  
  1590. /* Convert a host long to a network long.  */
  1591.  
  1592. extern __inline__ unsigned long
  1593. htonl (unsigned long __arg)
  1594. {
  1595.   return __arg;
  1596. }
  1597.  
  1598. /* Convert a host short to a network short.  */
  1599.  
  1600. extern __inline__ unsigned short
  1601. htons (unsigned int __arg)
  1602. {
  1603.   return __arg;
  1604. }
  1605.  
  1606. #endif /* big-endian */
  1607.  
  1608. /* Convert a network long to a host long.  */
  1609.  
  1610. extern __inline__ unsigned long
  1611. ntohl (unsigned long __arg)
  1612. {
  1613.   return htonl (__arg);
  1614. }
  1615.  
  1616. /* Convert a network short to a host short.  */
  1617.  
  1618. extern __inline__ unsigned short
  1619. ntohs (unsigned int __arg)
  1620. {
  1621.   return htons (__arg);
  1622. }
  1623.  
  1624. __EOF__
  1625.  
  1626. if [ -r ${INPUT}/sys/byteorder.h ]; then
  1627.   if grep BYTE_ORDER ${INPUT}/sys/byteorder.h >/dev/null 2>/dev/null; then
  1628.     cat <<'__EOF__' >>${LIB}/sys/byteorder.h
  1629. #ifndef BYTE_ORDER
  1630. #define LITTLE_ENDIAN __LITTLE_ENDIAN__
  1631. #define BIG_ENDIAN __BIG_ENDIAN__
  1632. #define PDP_ENDIAN __PDP_ENDIAN__
  1633. #define BYTE_ORDER __BYTE_ORDER__
  1634. #endif
  1635.  
  1636. __EOF__
  1637.   fi
  1638. fi
  1639.  
  1640. cat <<'__EOF__' >>${LIB}/sys/byteorder.h
  1641. #endif /* !defined (_SYS_BYTEORDER_H) */
  1642. __EOF__
  1643.  
  1644. chmod a+r ${LIB}/sys/byteorder.h
  1645.  
  1646. exit 0
  1647.  
  1648.